package com.itboye.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.itboye.shop.R;
import com.itboye.shop.bean.ShopCarBean;
import com.itboye.shop.util.helper.ImageLoader;
import com.itboye.shop.util.loadutil.Const;

import java.util.List;

/**
 * 失效的购物车商品
 */

public class OldShopCarAdapter extends BaseAdapter {
    Context context;
    List<ShopCarBean.GoodsEntity> list;


    public OldShopCarAdapter(Context context,List<ShopCarBean.GoodsEntity> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.item_old_shopcart,null);
            holder.old_shop_img= (SimpleDraweeView) view.findViewById(R.id.old_shop_img);
            holder.old_shop_title= (TextView) view.findViewById(R.id.old_shop_title);
            holder.old_shop_content= (TextView) view.findViewById(R.id.old_shop_content);
            holder.old_shop_num= (TextView) view.findViewById(R.id.old_shop_num);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        ImageLoader.loadImage(holder.old_shop_img, Const.IMAGE_HEAD
                + list.get(position).getIcon_url());
        holder.old_shop_title.setText(list.get(position).getName());
        if(list.get(position).getItem_status().equals("2")){
            holder.old_shop_content.setText("该商品已下架");
        }else   if(list.get(position).getItem_status().equals("3")){
            holder.old_shop_content.setText("该商品已下架");
        }else   if(list.get(position).getItem_status().equals("4")){
            holder.old_shop_content.setText("该商品库存已不足");
        }else   if(list.get(position).getItem_status().equals("5")){
            holder.old_shop_content.setText("该商品被删除");
        }
        holder.old_shop_num.setText(list.get(position).getCount());
        return view;
    }

    class ViewHolder{
        SimpleDraweeView old_shop_img;
        TextView old_shop_title,old_shop_content,old_shop_num;
    }
}
